Skip to content

Conversation

@nitishfy
Copy link
Member

@nitishfy nitishfy commented Dec 22, 2025

The existing argocd cert add-tls command had two key issues with handling TLS certificates:

  1. Previously, the command rejected certificates with the same subject, even if the actual certificate data was different (e.g., renewed or rotated certificates). This caused valid certificates to be incorrectly skipped, preventing users from storing multiple valid TLS certs for the same server.

  2. The command displayed the number of RepositoryCertificate items returned by the API as the number of certificates added. Since the API returns a single object per server regardless of how many PEM blocks are included, the message could misleadingly indicate 0 certificates were stored, confusing users.

After

> argocd cert add-tls repo.example.com --from duplicate.pem
Reading TLS certificate data in PEM format from 'duplicate.pem'
WARNING: Duplicate certificate detected (SHA256 fingerprint 25734613d11c3b40f1772cf8d01536b198a77dad2877f7350984a8859545e68b, subject 'CN=repo.example.com'), skipping.
Created entry with 1 PEM certificates for repository server repo.example.com

❯ argocd cert rm repo.example.com
Removed cert for 'repo.example.com' of type 'https' (subtype '')

❯argocd cert add-tls repo.example.com --from same-subject.pem
Reading TLS certificate data in PEM format from 'same-subject.pem'
Created entry with 2 PEM certificates for repository server repo.example.com

❯ argocd cert list | grep repo.example.com
repo.example.com         https  rsa                  CN=repo.example.com
repo.example.com         https  rsa                  CN=repo.example.com

Checklist:

  • Either (a) I've created an enhancement proposal and discussed it with the community, (b) this is a bug fix, or (c) this does not need to be in the release notes.
  • The title of the PR states what changed and the related issues number (used for the release note).
  • The title of the PR conforms to the Title of the PR
  • I've included "Closes [ISSUE #]" or "Fixes [ISSUE #]" in the description to automatically close the associated issue.
  • I've updated both the CLI and UI to expose my feature, or I plan to submit a second PR with them.
  • Does this PR require documentation updates?
  • I've updated documentation as required by this PR.
  • I have signed off all my commits as required by DCO
  • I have written unit and/or e2e tests for my change. PRs without these are unlikely to be merged.
  • My build is green (troubleshooting builds).
  • My new feature complies with the feature status guidelines.
  • I have added a brief description of why this PR is necessary and/or what this PR solves.
  • Optional. My organization is added to USERS.md.
  • Optional. For bug fixes, I've indicated what older releases this fix should be cherry-picked into (this may or may not happen depending on risk/complexity).

@nitishfy nitishfy requested review from a team as code owners December 22, 2025 17:01
@bunnyshell
Copy link

bunnyshell bot commented Dec 22, 2025

🔴 Preview Environment stopped on Bunnyshell

See: Environment Details | Pipeline Logs

Available commands (reply to this comment):

  • 🔵 /bns:start to start the environment
  • 🚀 /bns:deploy to redeploy the environment
  • /bns:delete to remove the environment

Signed-off-by: nitishfy <[email protected]>
// certFingerprintSHA256 returns the SHA256 fingerprint of the given X.509 certificate.
// The fingerprint is returned as a lowercase hexadecimal string.
func certFingerprintSHA256(cert *x509.Certificate) string {
sum := sha256.Sum256(cert.Raw)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is just a question. Using cert.Raw treats certificate renewals with the same public key as distinct certificates. Is this intentional?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, this is intentional. The goal of this change is to deduplicate identical certificate data, not to collapse logically related certificates.

@nitishfy nitishfy requested a review from chansuke January 2, 2026 10:34
@olivergondza
Copy link
Contributor

This looks good to me! Since I agree that certificate renewal is a prominent use case for subject collisions, how about adding expiration dates into argocd cert list output to distinguish the most likely difference?

Comment on lines +152 to +156
for _, entry := range pems {
x509cert, err := certutil.DecodePEMCertificateToX509(entry)
if err != nil {
return nil, err
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider wrapping the error with the index so users know which PEM block failed.

Suggested change
for _, entry := range pems {
x509cert, err := certutil.DecodePEMCertificateToX509(entry)
if err != nil {
return nil, err
}
for i, entry := range pems {
x509cert, err := certutil.DecodePEMCertificateToX509(entry)
if err != nil {
return nil, fmt.Errorf("failed to decode certificate at index %d: %w", i, err)
}

errors.CheckError(err)

fmt.Printf(
"Created/updated TLS certificate entry for repository server %s with %d unique PEM certificates\n",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can we differentiate the message between creation and update to give the user a more exact information?

errors.CheckError(err)

fmt.Printf(
"Created/updated TLS certificate entry for repository server %s with %d unique PEM certificates\n",
Copy link
Contributor

@ppapapetrou76 ppapapetrou76 Jan 12, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also minor but why is this broken in two lines?

// Two certificates are considered duplicates if their SHA256 fingerprints match.
// The function returns a slice of unique certificates in the original order.
// If any certificate cannot be decoded into X.509 format, an error is returned.
func deduplicatePEMCertificates(pems []string) ([]string, error) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would you consider to just log a warning if a certificate cannot be decoded, and continue with the next one instead of returning an error?

fingerprint := certFingerprintSHA256(x509cert)

if _, exists := fingerprintMap[fingerprint]; exists {
fmt.Printf(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please use fmt.Fprintf(os.Stderr, .... instead
this will allow users to capture output consistently

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants